package com.kunya.product.service.impl.product;

import com.kunya.common.common.ResponseCode;
import com.kunya.common.common.ServerResponse;
import com.kunya.product.dao.product.ProductParameterMapper;
import com.kunya.product.po.ProductParameter;
import com.kunya.product.service.product.IProductParameterService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author zp
 * @Description: 商品参数service实现类
 * @date 2018/6/13 17:26
 */
@Service("iProductParameter")
public class ProductParameterServiceImpl implements IProductParameterService {

    @Autowired
    private ProductParameterMapper productParameterMapper;

    /**
     * @author zp
     * @Description: 根据商品id获取商品参数列表
     * @param
     * @date 2018/6/13 18:08
     */
    public ServerResponse<List<ProductParameter>> getProductParametersByProductId(Long productId,String tablePrefix){
        if(productId==null) {
            return ServerResponse.createByErrorCodeMessage(ResponseCode.ILLEGAL_ARGUMENT.getCode(), "参数错误");
        }
        List<ProductParameter> productParameterList=productParameterMapper.selectProductParametersByProductId(productId,tablePrefix);
        if(CollectionUtils.isEmpty(productParameterList)){
            return  ServerResponse.createByErrorMessage("商品参数不存在");
        }
        return ServerResponse.createBySuccess(productParameterList);
    }

    @Override
    public ServerResponse deleteProductParameterByProductId(Long productId, String tablePrefix) {
        return productParameterMapper.deleteProductParameterByProductId(productId,tablePrefix)>0?
                ServerResponse.createBySuccess("删除商品参数成功"):ServerResponse.createByErrorMessage("删除商品参数失败");
    }
}
